﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jzy.Core.Common;
using FortuneHeavenCommon.DataMap;

namespace FortuneHeavenDAL
{
    public class NetBarDAL : BaseDAL
    {
        /// <summary>
        /// 用ID号获取Name,ID,GoldValue三列的值
        /// </summary>
        /// <remarks>
        /// author:huangshenyu
        /// </remarks>
        /// <param name="id">ID值</param>
        /// <returns>查不到返回null</returns>
        public NetBarInfo GetNetBarInforsNameIDGoldValue(int id)
        {
            string sql =string.Format(@"select [ID],[Name],[GoldValue] from NetBar where ID = '{0}'",id);
            List<NetBarInfo> list = dbOper.Query<NetBarInfo>(sql);
            if (list == null)
                return null;
            return list[0];
        }

        public List<NetBarInfo> GetNetBarInforsNameID()
        {
            string sql = @"select [ID],[Name] from NetBar";
            List<NetBarInfo> list = dbOper.Query<NetBarInfo>(sql);
            return list;
        }

        public List<NetBarInfo> GetNetBarInfors(int page, int size)
        {
            if (page <= 0)
            {
                page = 1;
            }
            string sql = @"select * from (
select [ID],[UserID],[Address],[Telephone],[Status],[Time],[Name],[MobileNumber],[Province],[City],[BarName],[GoldValue]
,ROW_NUMBER() OVER(ORDER BY ID DESC) ROW 
from NetBar) FF
 WHERE FF.ROW BETWEEN  @p0 AND @p1";
            List<NetBarInfo> list = dbOper.Query<NetBarInfo>(sql, size * (page - 1) + 1, size * page);
            return list;
        }

        public int GetTotalSize()
        {
            string sql = @"select count(id) from NetBar ";
            return dbOper.GetScalar<int>(sql);
        }
    }
}
